package problema003;

public class PrimeFactor {
	
	public static void main(String[] args){
		System.out.println(largestPrimeFactor());
	}
	
	public static int largestPrimeFactor(){
		double numero = 600851475143.0;
		int res = 0;
		double hasta = Math.sqrt(numero); int hastaI = (int) hasta;
		while(hastaI > 0){
			if(esPrimo(hastaI)){
				if(numero % hastaI == 0) return hastaI;
			}
			hastaI--;
		}
		return res;
	}
	
	
	public static boolean esPrimo(double num){
		double hasta = Math.sqrt(num);
		int hastaI = (int) hasta;
		for(int i = 2; i < hastaI; i++){
			if(num % i == 0) return false;
		}
		return true;
	}
}
